// Round
DLSS.Round = Ext.data.Record.create([
    {name: 'id'},
    {name: 'name', type: 'string'},
    {name: 'time', type: 'string'},
    {name: 'rank', type: 'string'},
    {name: 'couplesNumber', type: 'string'},
    {name: 'minSuccCouples', type: 'string'},
    {name: 'maxSuccCouples', type: 'string'},
    {name: 'mode', type: 'string'},
    {name: 'passingScore', type: 'string'},
    {name: 'setsNumber', type: 'string'},
    {name: 'finalDanceTime', type: 'string'},
    {name: 'reDance', type: 'string'}
]);
DLSS.roundsReader = new Ext.data.XmlReader({record:'round'},
    ['id','name','time','rank','couplesNumber','minSuccCouples','maxSuccCouples','mode',
    'passingScore','setsNumber','finalDanceTime','reDance'], DLSS.Round);
    	
DLSS.roundsStore = new Ext.data.Store({
	url: 'roundsList.htm',
    reader: DLSS.roundsReader,
    sortInfo:{field:'name', direction:'ASC'}
});

DLSS.roundsColumnModel = new Ext.grid.ColumnModel([
   {id:'round', header:"Name", width: 70, sortable: true, dataIndex: 'name', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Time", width: 70, sortable: true, dataIndex: 'time', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Rank", width: 25, sortable: true, dataIndex: 'rank', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Couples number", width: 50, sortable: true, dataIndex: 'couplesNumber', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Min couples", width: 40, sortable: true, dataIndex: 'minSuccCouples', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Max couples", width: 40, sortable: true, dataIndex: 'maxSuccCouples', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Mode", width: 25, sortable: true, dataIndex: 'mode', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Passing score", width: 45, sortable: true, dataIndex: 'passingScore', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Sets number", width: 40, sortable: true, dataIndex: 'setsNumber', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Final dance time", width: 50, sortable: true, dataIndex: 'finalDanceTime', editor: new Ext.form.TextField({allowBlank: false})},
   {header: "Redance", width: 30, sortable: true, dataIndex: 'reDance', editor: new Ext.form.TextField({allowBlank: false})}
]);
DLSS.roundsColumnModel.defaultSortable = true;

DLSS.roundsGrid = new Ext.grid.EditorGridPanel({
	cellCls:'round-management-table',
	store: DLSS.roundsStore,
	cm: DLSS.roundsColumnModel,
	style:'margin-left:10px;margin-top:20px;',
	width:900,
	height:150,
	autoExpandColumn:'name',
	title:'Rounds',
	frame:true,
	viewConfig: {forceFit: true},
	clicksToEdit:2,
     tbar: [{
         text: 'Add',
         handler : function(){
             var u = new DLSS.Round({name:'',time:'',rank:'',couplesNumber:'',minSuccCouples:'',maxSuccCouples:'',
    								 mode:'',passingScore:'',setsNumber:'',finalDanceTime:'',reDance:''});
             DLSS.roundsGrid.stopEditing();
             DLSS.roundsStore.insert(0, u);
             DLSS.roundsGrid.startEditing(0, 0);
             DLSS.roundsGrid.fireEvent('afteredit',{record:u, grid:DLSS.roundsGrid, row:0});
         }
     	},{
         text: 'Remove',
         handler:function() {
             if (!DLSS.roundsGrid.getSelectionModel().hasSelection()) {
                 Ext.Msg.show({title:'Information', msg: 'First select a round.',
                     buttons: Ext.Msg.OK,
                     animEl: DLSS.roundsGrid.getTopToolbar().items.get(1).getEl(),
                     icon: Ext.Msg.INFO
                 });
                 return;
             }
             var row = DLSS.roundsGrid.getSelectionModel().getSelectedCell()[0];
             var r = DLSS.roundsGrid.getStore().getAt(row);
             Ext.Msg.show({
                 title:'Warning!',
                 msg: 'Are you realy want to delete round '+r.get('name')+'?',
                 buttons: Ext.Msg.YESNO,
                 fn: function(buttonId){
                     if (buttonId!='yes') return;
                     Ext.Ajax.request({
                         url:'roundDelete.htm',
                         params:{id:this.r.get('id')},
                         success:function() {this.s.remove(this.r);},
                         scope:this,
                         method:'POST'
                     })
                 },
                 scope:{r:r,s:DLSS.roundsGrid.getStore()},
                 animEl: DLSS.roundsGrid.getTopToolbar().items.get(1).getEl(),
                 icon: Ext.Msg.QUESTION
             });
         }
     }]
});
DLSS.roundsGrid.on('afteredit', DLSS.submitRound,this);
      	
// Round CRUD form

// Modal Round window